﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using AtDevice;

namespace Mokkula
{
    public partial class StatisticsControl : UserControl
    {
        private StatisticsDrawer _drawer = new StatisticsDrawer();

        public StatisticsControl()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
            this.BackColor = Color.Black;
            this.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Margin = Padding.Empty;

            DeviceHandler.DeviceOpened += delegate(AtDevice.AtDevice device)
            {
                device.GetHuaweiInterface().FlowUpdated += new FlowInfoDelegate(StatisticsControl_FlowUpdated);
            };

            _drawer.AddItem(new DataRow("Download", Pens.Blue));
            _drawer.AddItem(new DataRow("Upload", Pens.DarkOrange));
        }

        void StatisticsControl_FlowUpdated(int uptime, int dlSpeed, int ulSpeed, long dlBytes, long ulBytes)
        {
            _drawer.Items[0].Data.Insert(0, dlSpeed / 1024);
            _drawer.Items[1].Data.Insert(0, ulSpeed / 1024);
            Invalidate();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            _drawer.DrawGraph(pe.Graphics, this.Size);
        }
    }
}
